package com.cqupt.slewing.welcome

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.Navigation
import com.cqupt.slewing.MyViewModel
import com.cqupt.slewing.R

class WelcomeFragment : Fragment() {
    private lateinit var myViewModel: MyViewModel
    private lateinit var buttonLogin: Button
    private lateinit var textViewRegister: TextView

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment_welcome, container, false)
        buttonLogin = view.findViewById(R.id.buttonRegister)
        textViewRegister = view.findViewById(R.id.textViewRegister)
        return view
    }

    override fun onViewStateRestored(savedInstanceState: Bundle?) {
        super.onViewStateRestored(savedInstanceState)
        myViewModel = ViewModelProvider(requireActivity())[MyViewModel::class.java]

        textViewRegister.setOnClickListener {
            val navController = Navigation.findNavController(it)
            navController.navigate(R.id.action_welcomeFragment_to_registerFragment)
        }
        buttonLogin.setOnClickListener {
            val navController = Navigation.findNavController(it)
            navController.navigate(R.id.action_welcomeFragment_to_loginFragment)
        }
    }
}